package com.example.designpatterns.interpreter.nonterminal;

import com.example.designpatterns.interpreter.Expression;
import java.util.Map;

/**
 * 加法表达式 - 非终结符表达式
 * 表示两个表达式相加
 */
public class AddExpression implements Expression {
    private Expression leftExpression;
    private Expression rightExpression;

    public AddExpression(Expression leftExpression, Expression rightExpression) {
        this.leftExpression = leftExpression;
        this.rightExpression = rightExpression;
    }

    @Override
    public int interpret(Map<String, Integer> context) {
        return leftExpression.interpret(context) + rightExpression.interpret(context);
    }
    
    @Override
    public String toString() {
        return "(" + leftExpression + " + " + rightExpression + ")";
    }
} 